#ifndef __OPRATION_H
#define __OPRATION_H
#include "bsp.h"
/**
 ****************************************************************************
 * @Warning 本程序未经作者许可，不得用于其它任何用途
 * @File    系统参数文件
 * @Author  xiaowine@cee0.com
 * @date    修改日期:2015年3月14日14:53:30
 * @version V1.0
 *************************************************
 * @brief   -->>include struct files
 ****************************************************************************
 * @attention
 * Powered By Xiaowine
 * <h2><center>&copy;  Copyright(C) 小酒论坛 2015-2019</center></h2>
 * All rights reserved
 *
 **/

/*************地址声明**************/

#define HimRangAddress    800
#define HimDisplayAddress 810
#define HimSParaAddress   900
#define HimSetAddress     1000

extern _uFLAG modbusFlag;
#define EEpExistFlag        modbusFlag.Bits.bit0
#define DataNeedRefreshFlag modbusFlag.Bits.bit1
#define DataTransFlag       modbusFlag.Bits.bit2
#define HMIOnLineFlag       modbusFlag.Bits.bit3
#define BEEPFlag            modbusFlag.Bits.bit4
#define Flag10msInterrupt   modbusFlag.Bits.bit5
#define Flag10ms            modbusFlag.Bits.bit6
#define warnFlag            modbusFlag.Bits.bit7

extern _uFLAG hmiKeyFlag;
#define HIMKEY0 hmiKeyFlag.Bits.bit0
#define HIMKEY1 hmiKeyFlag.Bits.bit1
#define HIMKEY2 hmiKeyFlag.Bits.bit2

extern ClkFg HIMReadClk;
extern ClkFg HIMWriteClk;
extern ClkFg CANSendClk;
extern ClkFg LEDSendClk;
extern ClkFg HIMConnectFlashClk;
extern ClkFg CanConnectFlashClk;

extern u16 CanCommunicationCount;
extern u16 HimCommunicationCount;
extern u16 beep10msCount;

typedef struct {
    int16_t startWarnDistance;
    int16_t nearestWarnDistance;
    int16_t period;
    int16_t rightWidth;
    int16_t leftWidth;
    int16_t angle;
    int16_t warnStartTime;
    int16_t warnLongbeepTime;
    int16_t data0;
    int16_t data1;
    int16_t data2;
    int16_t D_VStatus;
    int16_t pc9Period;
    int16_t warnSpeed;
    int16_t overSpeed;
} opration_t;
typedef struct {
    u8 head;
    u8 len;
    u8 addr;
    u8 cmd;
    u8 leftWidth;
    u8 angle;
} ledbuff_t;
extern opration_t optData;
extern double     tan_angle;
extern double     sqrt_angle;

#define BEEP_ON_TIME 30  // time*10ms

/*************本地函数声明**************/
void ReadHIM(void);
void WriteHIM(void);
void SendCan(void);
void SendLED(void);
void BEEPopt(void);
void TimeOutOpration(void);
void OprateCanRec(CanRxMsg *RecCache);
void readDataEeData(void);
void writeDataEeData(void);
void beepPin(uint8_t state);

#endif
